package com.dletc.dao.Impl;

import com.dletc.dao.DishDao;
import com.dletc.dao.OrderDao;
import com.dletc.domain.Dish;
import com.dletc.domain.Order;
import com.dletc.domain.Users;
import org.junit.Test;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class OrderDaoTest {

    OrderDao orderDao = new OrderDaoImpl();

    //添加订单测试
    @Test
    public void AddOrderByUser(){
        //用户登录账号 USerID已知道
        Users users =new Users(1,"sam","124567",0);
        DishDao dishDao = new DishDaoImpl();

        //用户点菜
        List<Dish> list = new ArrayList<>();
        list.add(dishDao.GetByID(1));
        list.add(dishDao.GetByID(3));

        for (Dish dish : list) {
            System.out.println(dish);
        }
        //创建一个订单对象,不需要给时间赋值，系统自动生成
        Order order = new Order(users.getUserID(), 0,list);
        orderDao.AddOrderByUser(order);

    }


    //商家获取所有订单
    @Test
    public void GetAllOrder(){
        List<Order> orders = orderDao.GetAllOrder();
        for (Order order : orders) {
            System.out.println(order);
        }
    }

    //顾客获取自己的所有订单
    @Test
    public void SelectByUserID(){
        DishDao dishDao = new DishDaoImpl();
        List<Dish> list = new ArrayList<>();
        list.add(dishDao.GetByID(1));
        Order order = new Order(1,0,list);
        List<Order> orders = orderDao.SelectByUserID(order);
        for (Order order1 : orders) {
            System.out.println(order1);
        }
    }

    //根据订单ID查询订单状态
    @Test
    public void  GetOrderIsDown(){
        int OrderID = 1;
        int isDown = orderDao.GetOrderIsDown(OrderID);
        System.out.println("1号订单是否完成："+isDown);
    }

    //根据订单ID修改订单状态
    @Test
    public void UpdateIsDown(){
        int OrderID =1;
        int IsDown = 1;
        orderDao.UpdateIsDown(OrderID,IsDown);
    }

}
